import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {BALANCE} from "../../api/balance.service";
import {CheckStandModel} from "../../model/checkstand.model";
import {ROUTER} from "../../service/router.service";
import {LocalStorage} from "../../utils/localstorage.utils";
import {USER} from "../../service/user.service";

/**
 * Generated class for the RechargePage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-recharge',
  templateUrl: 'recharge.html',
})
export class RechargePage {

  data:any={};

  moneyItems = [
    {name: '50元', value: 50},
    {name: '100元', value: 100},
    {name: '300元', value: 300},
    {name: '500元', value: 500},
    {name: '1000元', value: 1000},
    {name: '3000元', value: 3000},
  ];

  constructor(public BALANCE: BALANCE,public navCtrl: NavController, public navParams: NavParams,
              public ls:LocalStorage,
              public ROUTER:ROUTER,
              public USER:USER
) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RechargePage');
  }
  doRecharge(){
    if (!this.data.money){
      this.USER.toast('请输入有效金额');
      return;
    }
    this.BALANCE.recharge(this.data,v=>{
      console.log(v)
      let checkstand = new CheckStandModel(v.rechargeSn,v.content,v.money,v.id,ROUTER.MYBALANCE)
      checkstand.setBalancePay();
      this.ls.setObject('checkstand',checkstand);
      this.ROUTER.go(ROUTER.CHECK);
    });
  }

}
